# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=glfw

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.4
pkgrel=1
pkgdesc="A free, open source, portable framework for OpenGL application development. (mingw-w64)"
arch=('any')
url="http://www.glfw.org/"
license=('custom:ZLIB')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
optdepends=()
conflicts=()
options=('staticlibs' 'strip')
source=(http://downloads.sourceforge.net/project/glfw/glfw/$pkgver/${_realname}-$pkgver.tar.gz)
sha1sums=('9b04309418ccbc74b2115d11198b7912669814ee')

build() {
  # Build static libs
  [[ -d ${srcdir}/static-${MINGW_CHOST} ]] && rm -rf ${srcdir}/static-${MINGW_CHOST}
  mkdir -p ${srcdir}/static-${MINGW_CHOST}
  cd ${srcdir}/static-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_C_COMPILER=${CARCH}-w64-mingw32-gcc \
    -DBUILD_SHARED_LIBS=ON \
    "../${_realname}-${pkgver}"
  make

  # Build shared libs
  [[ -d ${srcdir}/shared-${MINGW_CHOST} ]] && rm -rf ${srcdir}/shared-${MINGW_CHOST}
  mkdir -p ${srcdir}/shared-${MINGW_CHOST}
  cd ${srcdir}/shared-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_C_COMPILER=${CARCH}-w64-mingw32-gcc \
    -DBUILD_SHARED_LIBS=OFF \
    "../${_realname}-${pkgver}"
  make
}

package() {
  cd "$srcdir/static-${MINGW_CHOST}"
  make install

  cd "${srcdir}/shared-${MINGW_CHOST}"
  make install
  mv ${pkgdir}${MINGW_PREFIX}/lib/glfw3dll.a ${pkgdir}${MINGW_PREFIX}/lib/libglfw3.dll.a

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/

  #copy license file
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  cp "${srcdir}/${_realname}-${pkgver}/COPYING.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
